Load packages and set options

library(tidyverse)
library(cowplot)
library(scales)
library(janitor)
library(tidytext)
library(mmbtools)
library(lubridate)
library(ggtext)
library(plotly)
library(crosstalk)
library(maps)
library(leaflet)

mmb_load_fonts()

Load data

post_offices <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-04-13/post_offices.csv')
mn_po <- post_offices %>% 
  filter(state == "MN", gnis_feature_class == "Post Office") %>% 
  mutate(years_open = ifelse(is.na(discontinued), 
                             2000 - established, 
                             discontinued - established))
mn_po_shared <- SharedData$new(mn_po, key ~id)
map <- leaflet(data = mn_po_shared) %>% 
  addTiles() %>%  
  # setView(lat = 46.7296, lng = -94.6859, zoom = 5) %>%
  addCircleMarkers(~longitude, ~latitude, radius = 1, label = ~gnis_orig_name)
plot <- 
  ggplot(data = mn_po_shared) +
  geom_point(aes(established, years_open))

plot_ly <- ggplotly(plot)
bscols(map, plot_ly)